package com.leetcode;

/**
 * 762. 二进制表示中质数个计算置位
 */
public class Solution762 {

    public int countPrimeSetBits(int left, int right) {
        int count = 0;
        for (int i = left; i <= right; i++) {
            if (isPrime(Integer.bitCount(i))) {
                count++;
            }
        }
        return count;
    }

    // 计算一个数是否是质数
    private boolean isPrime(int x) {
        if (x < 2) {
            return false;
        }
        for (int i = 2; i * i <= x; i++) {
            if (x % i == 0) {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        int left = 6;
        int right = 10;
        int count = new Solution762().countPrimeSetBits(left, right);
        System.out.println(count);
        System.out.println(36 % 6);
    }
}
